//worksheet.js
import React, {Component} from 'react';
import CommRow from './commRow.js';
import TableHead from './tableHead'
import { Parser as FormulaParser } from 'hot-formula-parser'
import {saveReport,getReportPattern} from "../../api/report_table";
import  FormulaInputCompoent from "./formulaInputCompoent.js";
import {Col, Input, message, Row} from "antd";


export default class CommTable extends Component {
        constructor(props) {
        super(props);
        this.state = {
           // report_id: this.props.match.params.id,
            history_record: [{
                data_model: {},   //数据 (是否显示数据)
                value_model:{},  //值
                cell_isThousandsFormat:{},  //还否千分位
                cell_isPercentageFormat:{},  //%
                cell_decimal_place:{}, //小数位数
                struct_model:{},  //表格结构
                cell_align_model:{},  //对齐方式
                cell_hiden_data_model:{},  //隐藏数据 数据不显示
                cell_border_top_model:{},  //边
                cell_border_bottom_model:{},
                cell_border_left_model:{},
                cell_border_right_model:{},
                cell_addFilter_bright_model:{},   //filter
                cell_cellBackgroundColor_model:{}, //背景色
                cell_cell_font_css_model:{},   //字体
                //cellSelectStates_model:{},    //是否去掉？
                cell_editing_model:{},
                colWidths:[], //列宽度数组
                rowHeights:[] //行高度数组
            }],
            selectCell1:[], //点击单元格1   记录点击的第一个单元格
            selectCell2:[], //点击单元格2
            // 0 无动作，1 表示点击  2表示按Ctrl点击
            userActionType:0,
            head_x:-999,   //点击拖动头的时候，头坐标
            head_x_col:-999, //点击的列
            head_x_mouseDown:0,  //点击拖动头的时候，点击拖动手柄的标志位  1 按下  0 没有
            mergeCellArray:[],   //存在的合并单元格数组
            formulaText:"cccv"
        };
        let r = this.props.rowNum;  //行数
        let c = this.props.colNum;  //列数
        let cellSelectStates=[];    //单元格是否被选中
        let data_init=[]; //初始化数据
        let value_model_init=[];
        let isThousandsFormat_init=[];   //千分位
        let isPercentageFormat_init=[]; //%
        let decimal_place_init=[];   //小数位数
            let struct_model_init=[];
        let cell_align_init=[]; //单元格初始化数据
        let cell_hiden_data_init=[];  //隐藏数据
        let cell_border_top_init=[];
        let cell_border_bottom_init=[];
        let cell_border_left_init=[];
        let cell_border_right_init=[];
        let cell_addFilter_bright_init=[];
        let cell_cellBackgroundColor_init=[];
        let cell_cell_font_css_init=[];
        let cell_editing_mode_init=[];
        let colWidths=[];
        let rowHeights=[];
//数据初始化
        for(let i=0;i<r;i++){
            cellSelectStates[i]=new Array();
            data_init[i]=new Array();
            value_model_init[i]=new Array();
            isThousandsFormat_init[i]=new Array();
            isPercentageFormat_init[i]=new Array();
            decimal_place_init[i]=new Array();

            struct_model_init[i]=new Array();
            cell_align_init[i]=new Array();
            cell_hiden_data_init[i]=new Array();
            cell_border_top_init[i]=new Array();
            cell_border_bottom_init[i]=new Array();
            cell_border_left_init[i]=new Array();
            cell_border_right_init[i]=new Array();
            cell_addFilter_bright_init[i]=new Array();
            cell_cellBackgroundColor_init[i]=new Array();
            cell_cell_font_css_init[i]=new Array();
            cell_editing_mode_init[i]=new Array();
            rowHeights[i]=20;
//设置表格每列宽度数组

            for(let j=0;j<c;j++){
                cellSelectStates[i][j]=false;
                data_init[i][j]=1;
                isThousandsFormat_init[i][j]=0;   //初始化都0 不搞千分位  1 是千分位
                isPercentageFormat_init[i][j]=0;  //初始化都0 不搞%  1是%
                decimal_place_init[i][j]=2;       //小数位数

                //value_model_init[i][j]={text:"1",type:"String"};
                value_model_init[i][j]="";
                // struct_model_init[i][j]=new Array();
                // struct_model_init[i][j][0]=1;
                // struct_model_init[i][j][1]=1;
                struct_model_init[i][j]=[1,1];   // ?[rowspan colspan]
                cell_align_init[i][j]=1; //1 左对齐 2 中间对齐  3 右对齐
                cell_hiden_data_init[i][j]=0;  //默认是0: 不隐藏   1 :隐藏
                cell_border_top_init[i][j]=0;
                cell_border_bottom_init[i][j]=0;
                cell_border_left_init[i][j]=0;
                cell_border_right_init[i][j]=0;
                cell_addFilter_bright_init[i][j]=0;
                cell_cellBackgroundColor_init[i][j]="#ffffff";
                cell_cell_font_css_init[i][j]=['microYH','medium','font-weight_normal','font-sytle_normal','none'];
                cell_editing_mode_init[i][j]=0;
            }
        }

        //cell_editing_mode_init[1][1]=1;
        for(let j=0;j<c;j++){
            colWidths[j]=200;
        }

        // data_init[2][2]=0;
        // data_init[2][3]=0;
        //
        //
        // struct_model_init[2][1][0]=1;
        // struct_model_init[2][1][1]=3;

        //this.state.mergeCellArray=[[2,1,2,3]];
        // console.log(s)
        // console.log("'/////////////////////////////")
        // console.log(cc)
//初始化
        this.state.history_record[this.state.history_record.length-1].data_model=data_init;
        this.state.history_record[this.state.history_record.length-1].value_model=value_model_init;
        this.state.history_record[this.state.history_record.length-1].cell_isThousandsFormat=isThousandsFormat_init;
        this.state.history_record[this.state.history_record.length-1].cell_isPercentageFormat=isPercentageFormat_init;
        this.state.history_record[this.state.history_record.length-1].cell_decimal_place=decimal_place_init;


            this.state.history_record[this.state.history_record.length-1].struct_model=struct_model_init;

        this.state.history_record[this.state.history_record.length-1].cell_align_model=cell_align_init;
        this.state.history_record[this.state.history_record.length-1].cell_hiden_data_model=cell_hiden_data_init;
        this.state.history_record[this.state.history_record.length-1].cell_border_top_model=cell_border_top_init;
        this.state.history_record[this.state.history_record.length-1].cell_border_bottom_model=cell_border_bottom_init;
        this.state.history_record[this.state.history_record.length-1].cell_border_left_model=cell_border_left_init;
        this.state.history_record[this.state.history_record.length-1].cell_border_right_model=cell_border_right_init;
        this.state.history_record[this.state.history_record.length-1].cell_addFilter_bright_model=cell_addFilter_bright_init;
        this.state.history_record[this.state.history_record.length-1].cell_cellBackgroundColor_model=cell_cellBackgroundColor_init;
        this.state.history_record[this.state.history_record.length-1].cell_cell_font_css_model=cell_cell_font_css_init;
        //this.state.history_record[this.state.history_record.length-1].cellSelectStates_model=cellSelectStates;
        this.state.history_record[this.state.history_record.length-1].colWidths=colWidths;
        this.state.history_record[this.state.history_record.length-1].rowHeights=rowHeights;
        this.state.history_record[this.state.history_record.length-1].cell_editing_model=cell_editing_mode_init;

        //this.tableIdentifier = `tableData-${props.id}`

        //FormulaParser相关

        // Initialize the formula parser on demand
        this.parser = new FormulaParser()

        // When a formula contains a cell value, this event lets us
        // hook and return an error value if necessary
        //Fired while retrieving cell value by its label (eq: B3, B$3, B$3, $B$3).
        this.parser.on('callCellValue', (cellCoord, done) => {
             const x = cellCoord.column.index + 1
             const y = cellCoord.row.index + 1
            //const x = cellCoord.column.index
            //const y = cellCoord.row.index

            // Check that the cell is not self referencing
            if (this.parser.cell.x === x && this.parser.cell.y === y) {
                throw this.parser.Error(this.parser.ERROR_REF)
            }
            let _value_model=
                this.state.history_record[this.state.history_record.length-1].value_model;
            // if (!this.state.data[y] || !this.state.data[y][x]) {
            //     return done('')
            // }
            if (!_value_model[y] || !_value_model[y][x]) {
                return done('')
            }


            // All fine
            //let r=this.state.data[y][x];
            let t1=this.state.history_record[this.state.history_record.length-1].value_model;
            console.log(t1);
            let t2=t1[y][x];
            console.log(t2)
            return done(t2)
        })

        // When a formula contains a range value, this event lets us
        // hook and return an error value if necessary
        this.parser.on('callRangeValue', (startCellCoord, endCellCoord, done) => {
            const sx = startCellCoord.column.index + 1
            const sy = startCellCoord.row.index + 1
            const ex = endCellCoord.column.index + 1
            const ey = endCellCoord.row.index + 1
            const fragment = []
            let _value_model=this.state.history_record[this.state.history_record.length-1].value_model;
            for (let y = sy; y <= ey; y += 1) {
                //const row = this.state.data[y]
                const row = _value_model[y]

                if (!row) {
                    continue
                }
                const colFragment = []

                for (let x = sx; x <= ex; x += 1) {
                    let value = row[x]
                    if (!value) {
                        value = ''
                    }
                    if (value.slice(0, 1) === '=') {
                        const res = this.executeFormula({ x, y }, value.slice(1))
                        if (res.error) {
                            throw this.parser.Error(res.error)
                        }
                        value = res.result
                    }
                    colFragment.push(value)
                }
                fragment.push(colFragment)
            }

            if (fragment) {
                done(fragment)
            }
        })
    }

    // 获取state数据 保存到后端
    saveTable=(param_report_id)=>{
            //读取state 保存到后端
        let _current_table_model =this.state.history_record[this.state.history_record.length -1];
        let  _formulas=this.getFormulaIntable(_current_table_model.value_model);
        let _mergeCellArray=this.state.mergeCellArray;
        let parm_table_mode={
            table_model:_current_table_model,
            mergeCellArray:_mergeCellArray,
            report_id:param_report_id,
            workSheet_id:param_report_id,
            workTable_id:param_report_id,
            formulas:_formulas
        }
                saveReport(parm_table_mode).then(
                    (res) => {
                        console.log("get test response:", res.code);
                        alert("保存成功");
                    },
                    (error) => {
                        console.log("get response failed!");
                        alert("失败");
            }
        );
    }

    //获取公式
    getFormulaIntable=(value_mode)=>{
        console.log("value_mode:"+value_mode);
        let _formulaArray=[];
        for(let i=0;i<value_mode.length;i++){
            for(let j=0;j<value_mode[i].length;j++)
            {
               // if(j==value_mode[i].length-1)
               // {
                    console.log("begin :value_mode[i][j]:"+i+";"+j+";"+value_mode[i][j]);
                    if(value_mode[i][j] && value_mode[i][j].slice(0,1)=="@"){
                        console.log("value_mode[i][j]:"+i+";"+j+";"+value_mode[i][j]);
                        //slice
                        _formulaArray.push(
                            {
                                rowNo:i,
                                colNo:j,
                                formula:value_mode[i][j]
                            }
                        );
                    }
              //  }
            }
        }
     return _formulaArray;
    }

    /**
     * Executes the formula on the `value` usign the FormulaParser object
     */
    executeFormula = (cell, value) => {
        this.parser.cell = cell
        console.log(value);
        let res = this.parser.parse(value)
        if (res.error != null) {
            console.log(res.error);
            return res // tip: returning `res.error` shows more details
        }
        if (res.result.toString() === '') {
            return res
        }
        if (res.result.toString().slice(0, 1) === '=') {
            // formula points to formula
            res = this.executeFormula(cell, res.result.slice(1))
        }
        return res
    }

    componentDidMount(){
        this.props.onRef(this)  //这个就是把自身传给调用者
        let _report_id=this.props.reportId;
        getReportPattern(_report_id).then(
            (res) => {
                let _table_mode={};
                let new_history_record=[];
                let _col_length=res.data.colwidthsList.length;
                let _row_length=res.data.rowheightsList.length;
                let _colwidths=[];
                let _rowHeights=[];

                let _data_mode=new Array(_rowHeights);
                let _value_mode=new Array(_rowHeights);
                let _struct_mode=new Array(_rowHeights);
                let _cell_align=new Array(_rowHeights);
                let _cell_hiden_data=new Array(_rowHeights);
                let _cell_isThousandsFormat=new Array(_rowHeights);
                let _cell_isPercentageFormat=new Array(_rowHeights);
                let _cell_decimal_place=new Array(_rowHeights);
                let _cell_border_top=new Array(_rowHeights);
                let _cell_border_right=new Array(_rowHeights);
                let _cell_border_bottom=new Array(_rowHeights);
                let _cell_border_left=new Array(_rowHeights);
                let _cell_cell_font_css=new Array(_rowHeights);
                let _cell_background_color=new  Array(_rowHeights);
                let _cell_addFilter_bright=new  Array(_rowHeights);
                let _cell_editing_model=new  Array(_rowHeights);



                for (var i=0;i<_row_length;i++){
                    _data_mode[i] = new Array(_col_length);
                    _value_mode[i]=new Array(_col_length);
                    _struct_mode[i]=new Array(_col_length);
                    _cell_align[i]=new Array(_col_length);
                    _cell_hiden_data[i]=new Array(_col_length);
                    _cell_isThousandsFormat[i]=new Array(_col_length);
                    _cell_isPercentageFormat[i]=new Array(_col_length);
                    _cell_decimal_place[i]=new Array(_col_length);
                    _cell_border_top[i]=new Array(_col_length);
                    _cell_border_right[i]=new Array(_col_length);
                    _cell_border_bottom[i]=new Array(_col_length);
                    _cell_border_left[i]=new Array(_col_length);
                    _cell_cell_font_css[i]=new Array(_col_length);
                    _cell_background_color[i]=new Array(_col_length);
                    _cell_addFilter_bright[i]=new Array(_col_length);
                    _cell_addFilter_bright[i].fill(0);
                    _cell_editing_model[i]=new Array(_col_length);
                    _cell_editing_model[i].fill(0);

                }


                // for (let i=0;i<_row_length;i++){
                //     for (let j=0;j<_col_length;j++){
                //     }
                // }

                _colwidths=res.data.colwidthsList.map(item => { // item为数组的元素
                    return item.value;
                });
                _rowHeights=res.data.rowheightsList.map(item => { // item为数组的元素
                    return item.value;
                });

                for(var val of res.data.modelList){
                    // if((val.rowno==2) && (val.colno==2)){
                    //     console.log("test~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
                    // }
                    _data_mode[val.rowno][val.colno]=val.isShow;
                    _value_mode[val.rowno][val.colno]=val.strValue;
                   // _struct_mode[val.rowno][val.colno]=[val.rowSpan,val.colSpan];
                    _struct_mode[val.rowno][val.colno]=new Array(2);
                    _struct_mode[val.rowno][val.colno][0]=val.rowSpan;
                    _struct_mode[val.rowno][val.colno][1]=val.colSpan;
                    _cell_align[val.rowno][val.colno]=val.align;
                    //todo
                    _cell_hiden_data[val.rowno][val.colno]=val.hiddenData;
                    //_cell_isThousandsFormat[val.rowno][val.colno]=val.isThousandsFormat;
                    _cell_isThousandsFormat[val.rowno][val.colno]=val.isThousandsFormat;
                    _cell_isPercentageFormat[val.rowno][val.colno]=val.isPercentageFormat;
                    _cell_decimal_place[val.rowno][val.colno]=val.decimalPlace;
                    _cell_border_top[val.rowno][val.colno]=val.topBorder;
                    _cell_border_right[val.rowno][val.colno]=val.rightBorder;
                    _cell_border_bottom[val.rowno][val.colno]=val.bottomBorder;
                    _cell_border_left[val.rowno][val.colno]=val.leftBorder;
                    _cell_cell_font_css[val.rowno][val.colno]=[val.fontFamily,val.fontSize,val.fontWeight,val.fontSytle,val.fontCssUnderline];
                    _cell_background_color[val.rowno][val.colno]=val.backgroundcolor
                }

                new_history_record[0]={
                    data_model:_data_mode,   //数据 (是否显示数据)
                    value_model:_value_mode,  //值
                    struct_model:_struct_mode,  //表格结构
                    cell_align_model:_cell_align,  //对齐方式
                    cell_hiden_data_model:_cell_hiden_data,
                    cell_isThousandsFormat:_cell_isThousandsFormat,  //千分位
                    cell_isPercentageFormat: _cell_isPercentageFormat, //%
                    cell_decimal_place: _cell_decimal_place, //%
                    cell_border_top_model:_cell_border_top,  //边
                    cell_border_bottom_model:_cell_border_bottom,
                    cell_border_left_model:_cell_border_left,
                    cell_border_right_model:_cell_border_right,
                    cell_addFilter_bright_model: _cell_addFilter_bright,   //filter
                    cell_cellBackgroundColor_model:_cell_background_color, //背景色
                    cell_cell_font_css_model:_cell_cell_font_css,   //字体
                    //cellSelectStates_model:{},    //是否去掉？
                    cell_editing_model:_cell_editing_model,
                    colWidths:_colwidths, //列宽度数组
                    rowHeights:_rowHeights //行高度数组
                }
              //  console.log( "''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''");

                console.log(new_history_record);
                //console.log( "''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''");
               this.setState({history_record: new_history_record});
               this.setState({mergeCellArray: res.data.mergecellarrayList});
                //this.setState({mergeCellArray: res.data.mergecellarrayList});
            },
            (error) => {
                console.log("get response failed!");
            }
        );
}

//处理单元格选择   主要是改变相关样式数据
    handleCellSelect = (e,i,j) => {
        console.log("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
       // console.log(e)
         if(e.ctrlKey){     // 按下ctrl key  不用重新
     //       if(this.state.userActionType==1){  //上次动作点击的是单元格
             const current_table_model =this.state.history_record[this.state.history_record.length -1];
             this.state.selectCell2=new Array(i, j);  //当前选中的单元格坐标
             let row_start= this.state.selectCell1[0]<i ? this.state.selectCell1[0] :i;
             let row_end= this.state.selectCell1[0]>i ? this.state.selectCell1[0] :i;
             let col_start= this.state.selectCell1[1]<j ? this.state.selectCell1[1] :j;
             let col_end= this.state.selectCell1[1]>j ? this.state.selectCell1[1] :j;
             //还是尽快把selectCell1、selectCell2的数字调整过来，selectCell1 表示左上角的单元格 selectCell2表示右下角单元格
             this.state.selectCell1=new Array(row_start, col_start);  //当前选中的单元格坐标
             this.state.selectCell2=new Array(row_end, col_end);  //当前选中的单元格坐标
             //执行下面方法 会根据情况修改 this.state.selectCell1、 this.state.selectCell2
             //this.adjuestSelectRange(this.state.mergeCellArray,[row_start,col_start,row_end,col_end])
             let b=this.validatingSelectRange(this.state.mergeCellArray,[row_start,col_start,row_end,col_end])
             if(!b){
                 message.info("选择的范围有误，请重选")
                 return;
             }

              row_start= this.state.selectCell1[0];
              row_end= this.state.selectCell2[0];
              col_start= this.state.selectCell1[1];

             this.clearCssFilter(current_table_model)
             col_end= this.state.selectCell2[1];;
             for (let i=row_start;i<=row_end;i++)
             {
                 for (let j=col_start;j<=col_end;j++){
                     current_table_model.cell_addFilter_bright_model[i][j]=1;  //范围内全部家filter
                 }
             }
             //setState 即可引发渲染
             this.setState({
                 history_record: this.state.history_record,
             });
            return;
     //       }
         }
        //复制一个history 元素，改变这个元素相关属性
        const history = this.state.history_record;
        const current =history.slice(history.length - 1)
        const table_model = current[0];
        //复制一个数组
        //let cellSelectStates_s=this.state.cellSelectStates;
        let cellSelectStates_s=table_model.cell_addFilter_bright_model ;
        let  _cell_editing_model=table_model.cell_editing_model;
        let cellSelectStates_temp=[];
        let _cell_editing_model_temp=[];

        for(let i=0;i<cellSelectStates_s.length;i++){
            cellSelectStates_temp.push(new Array(cellSelectStates_s[i].length).fill(0));
        }
        for(let i=0;i<_cell_editing_model.length;i++){
            _cell_editing_model_temp.push(new Array(_cell_editing_model[i].length).fill(0));
        }

        cellSelectStates_temp[i][j]=1;  //1表示选中
        table_model.cell_addFilter_bright_model=cellSelectStates_temp;
        table_model.cell_editing_model=_cell_editing_model_temp;
        this.state.selectCell1=new Array(i, j);  //当前选中的单元格坐标
        this.state.selectCell2=[];  //清除上一次ctrl+click数据
        this.state.userActionType=1; //这个动作记录用户上次的操作
        this.state.formulaText=table_model.value_model[i][j];
        let v=table_model.value_model[i][j];
        //alert(v)
        console.log("++++++++++++++++++++++++++++++++++++++++=")
        console.log(v)
        this.setState({
            history_record: history.concat(table_model),
           // formulaText:v
        });
    }

//核心是修改select、editing 2个标志
    handleCellDoubleClick= (e,i,j) => {
        //复制一个history 元素，改变这个元素相关属性
        const history = this.state.history_record;
        const current =history.slice(history.length - 1)
        const table_model = current[0];
        //复制一个数组
        //let cellSelectStates_s=this.state.cellSelectStates;
        let cellSelectStates_s=table_model.cell_addFilter_bright_model ;
        let _cell_editing_model=table_model.cell_editing_model;
        let cellSelectStates_temp=[];
        let _cell_editing_model_temp=[];

        for(let i=0;i<cellSelectStates_s.length;i++){
            cellSelectStates_temp.push(new Array(cellSelectStates_s[i].length).fill(0));
        }

        for(let i=0;i<_cell_editing_model.length;i++){
            _cell_editing_model_temp.push(new Array(_cell_editing_model[i].length).fill(0));
        }

        //cellSelectStates_temp[i][j]=1;  //1表示选中
        _cell_editing_model_temp[i][j]=1;  //1表示选中
        table_model.cell_addFilter_bright_model=cellSelectStates_temp;
        table_model.cell_editing_model=_cell_editing_model_temp;

        this.state.selectCell1=new Array(i, j);  //当前选中的单元格坐标
        this.state.selectCell2=[];  //清除上一次ctrl+click数据
        //this.state.userActionType=1; //这个动作记录用户上次的操作

        this.setState({
            history_record: history.concat(table_model),
        });
    }


    //核心是修改select、editing 2个标志  editing
    transformState_edit = (table_model,i,j,editing_value,selected_value) => {
        let _cellSelectStates_s=table_model.cell_addFilter_bright_model ;
        let _cell_editing_model=table_model.cell_editing_model;
        let _cellSelectStates_temp=[];
        let _cell_editing_model_temp=[];

        for(let i=0;i<_cellSelectStates_s.length;i++){
            _cellSelectStates_temp.push(new Array(_cellSelectStates_s[i].length).fill(0));
        }

        for(let i=0;i<_cell_editing_model.length;i++){
            _cell_editing_model_temp.push(new Array(_cell_editing_model[i].length).fill(0));
        }
        _cellSelectStates_temp[i][j]=selected_value;  //1表示选中
        _cell_editing_model_temp[i][j]=editing_value;  //0表示选中
        table_model.cell_addFilter_bright_model=_cellSelectStates_temp;
        table_model.cell_editing_model=_cell_editing_model_temp;
       // return table_model;
    }






    /**
     * Handles changing a cell, stores the new data state and stores into
     * local model
     */
    handleChangedCell = (i,j, value) =>{
        const history = this.state.history_record;
        const current =history.slice(history.length - 1)
        const table_model = current[0];
        //let cellSelectStates_s=table_model.cell_addFilter_bright_model ;
        //let _cell_editing_model=table_model.cell_editing_model;
        //table_model.value_model[i][j].text=value;
        table_model.value_model[i][j]=value;
        //改变编辑状态和选择状态
        this.transformState_edit(table_model,i,j,0,1);

        this.state.selectCell1=new Array(i, j);  //当前选中的单元格坐标
        this.state.selectCell2=[];  //清除上一次ctrl+click数据

        this.setState({
            history_record: history.concat(table_model),
        });
    }


    //调整选择范围 mergeCellArray 已合并单元格数组,selectrectangle 选择范围的坐标 是个一维数组
    adjuestSelectRange=(mergeCellArray, selectrectangle)=>{
        let isNotCross=mergeCellArray.every((rectangle1)=>this.changeRectangle(rectangle1,selectrectangle));
        if (isNotCross==true) {
            return;
        }else{
            let selectrectangle=[...this.state.selectCell1,...this.state.selectCell2];
            //这个时候的selectrectangle 是已经调整过的了
            this.adjuestSelectRange(mergeCellArray,selectrectangle);
        }
    };

    validatingSelectRange=(mergeCellArray, selectrectangle)=>{
        let isNotCross=mergeCellArray.every((rectangle1)=>this.isNotCorss(rectangle1,selectrectangle));
        return isNotCross;
    };


    //返回true 即不相交 ，返回false  则相交

    //react1  是个一维数组[rowPosition1  0,colPosition1  1,rowPosition2 2,colPosition2 3] 左上 右下
    changeRectangle=(rectangle, selectRect)=>{
        let b=selectRect[3] < rectangle[1] ||  //选择区域在合并单元格左边的情况
            selectRect[1]  > rectangle[3] ||   //选择的单元格在单元格右边的情况
            selectRect[2] < rectangle[0]  ||   //上边
            selectRect[0]  >rectangle[2]      //下边;
         if(!b){  //继续判断selectRect是否包含了rectangle
             if(selectRect[0]<=rectangle[0] &&
                selectRect[2]>=rectangle[2] &&
                selectRect[1]<=rectangle[1] &&
                selectRect[3]>=rectangle[3]
             )b=true;
   }

        if(b){
            return true;  //不相交
        }else{
            //调整范围selectRect2  以下不要删除  留着以后用 目前只是简化处理！！！xj
            let row_start= rectangle[0]<selectRect[0] ? rectangle[0] :selectRect[0];
            let row_end=rectangle[2]<selectRect[2] ? selectRect[2]:rectangle[2];
            let col_start= rectangle[1]<selectRect[1] ? rectangle[1] :selectRect[1];;
            let col_end= rectangle[3]<selectRect[3] ? selectRect[3] :rectangle[3];
            this.state.selectCell1=[row_start,col_start];
            this.state.selectCell2=[row_end,col_end];
            return false;
        }
    }



//    //返回true 即不相交 ，返回false  则相交判断2个集合描述 范围是否会相交[rowPosition1  0,colPosition1  1,rowPosition2 2,colPosition2 3]
    isNotCorss=(rectangle, selectRect)=>{
        let b=selectRect[3] < rectangle[1] ||  //选择区域在合并单元格左边的情况
            selectRect[1]  > rectangle[3] ||   //选择的单元格在单元格右边的情况
            selectRect[2] < rectangle[0]  ||   //上边
            selectRect[0]  >rectangle[2]      //下边;
        if(!b){  //继续判断selectRect是否包含了rectangle
            if(selectRect[0]<=rectangle[0] &&
                selectRect[2]>=rectangle[2] &&
                selectRect[1]<=rectangle[1] &&
                selectRect[3]>=rectangle[3]
            )b=true;
        }

        if(b){
            return true;  //不相交
        }else{
            return false;
        }
    }



    //点击表头拖动手柄的事件处理
    handleCellMouseDown=(event,i)=>{
        let x=parseInt(event.clientX);
        let y=parseInt(event.clientY);
        //按下了拖动手柄
        this.state.head_x=x;
        this.state.head_x_col=i;
        this.state.head_x_mouseDown=1;

        //点击改变宽度的实现
        let colWidths=this.state.history_record[this.state.history_record.length-1].colWidths;
        let l=colWidths[i];
        if(event.ctrlKey){
             l=l-20;
        }else{
            l=l+20;
        }
            if (l<=1) l=1;
        if (l>800) l=800;
        colWidths[i]=l;
        //setState 即可引发渲染
        this.setState({
            history_record: this.state.history_record,
        });
    }


    //点击表头拖动手柄的事件处理
    handleRowHeadMouseDown=(event, i)=>{
        let x=parseInt(event.clientX);
        let y=parseInt(event.clientY);
        //按下了拖动手柄
        // this.state.head_x=x;
        // this.state.head_x_col=i;
        // this.state.head_x_mouseDown=1;

        //点击改变宽度的实现
        let rowHeights=this.state.history_record[this.state.history_record.length-1].rowHeights;
        let l=rowHeights[i];
        if(event.ctrlKey){
            l=l-5;
        }else{
            l=l+5;
        }
        if (l<=1) l=1;
        if (l>500) l=500;
        rowHeights[i]=l;
        //setState 即可引发渲染
        this.setState({
            history_record: this.state.history_record,
        });
        //点击改变宽度的实现 结束
    }


    //点击表头拖动手柄后马上松开的事件处理
    handleCellMouseUp=(e,i)=>{
        this.state.head_x=-999;
        this.state.head_x_mouseDown=0;
        //console.log("handleCellMouseUphandleCellMouseUphandleCellMouseUphandleCellMouseUphandleCellMouseUp")
    }


    //表头上发生MouseUp事件的处理
    handleTableHeadMouseUp=(event)=>{
        let x=parseInt(event.clientX);
      // console.log("tabletabletabletabletabletabletabletable:"+x);
        let y=parseInt(event.clientY);
       if(this.state.head_x_mouseDown==1){
           let d=x-this.state.head_x;
           this.state.head_x=-999;
           this.state.head_x_mouseDown=0;
           let i=this.state.head_x_col;
           let colWidths=this.state.history_record[this.state.history_record.length-1].colWidths;

           let l=colWidths[i]+d;
           if (l<=1) l=1;
           if (l>400) l=400;
           colWidths[i]=l;
           //setState 即可引发渲染
           this.setState({
               history_record: this.state.history_record,
           });
       }
    }


    //追加行
    appendRow=(insertRowType)=>{
        //复制一个history 元素，改变这个元素相关属性
        const history = this.state.history_record;
        const current =history.slice(history.length - 1)
        const table_model = current[0];
        insertRowType=insertRowType|| -1;
        let r=this.appendRowInModel(table_model,insertRowType);
        if(r==-1) return;
        let newTable_model=r;
        this.setState({
            history_record: history.concat(newTable_model),
        });
    }
   //insertRowType=-1 是追加行
   // insertRowType=-2 是插入行  当前位置从state当中取出
   //insertRowType=-3 是删除行
    appendRowInModel=(table_model,insertRowType)=>{
        //取得当前行位置 即读取点击的位置，如果没有点击数据  有2种处理，1、啥都不干 2、追加到最后一行
        let p1=-1;
        let p2=-1;
        if(this.state.selectCell1.length==2){
            p1=this.state.selectCell1[0];
        }
        if(this.state.selectCell2.length==2){
            p2=this.state.selectCell2[0];
        }
        //插入行 删除行 必须指定位置
        if(insertRowType==-2 || insertRowType==-3){
            if (p1==-1){
                alert("请选择一行再执行相关操作")
                return -1;}
            if(p2!=-1  && p1!=p2){
                alert("仅能选择一行再执行相关操作")
                return -1;
            }
        };


        let data_model=table_model.data_model ;  //是个2维数组
        let l=data_model.length - 1;  //最后一行
        if((p1==0 || p1==l) && insertRowType==-3){
            alert('首行、末行不能删除');
            return -1;
        }

        if(insertRowType==-1){
            this.copyArrayLastRow(table_model.data_model);
            //this.cloneObjIn2DimArray(table_model.value_model,-1);
            this.copyArrayLastRow(table_model.value_model);
            this.copyArrayLastRow(table_model.cell_align_model);
            this.copyArrayLastRow(table_model.cell_isThousandsFormat);
            this.copyArrayLastRow(table_model.cell_isPercentageFormat);
            this.copyArrayLastRow(table_model.cell_decimal_place);
            this.copyArrayLastRow(table_model.cell_border_top_model);
            this.copyArrayLastRow(table_model.cell_border_bottom_model);
            this.copyArrayLastRow(table_model.cell_border_left_model);
            this.copyArrayLastRow(table_model.cell_border_right_model);
            this.copyArrayLastRow(table_model.cell_addFilter_bright_model);
            this.copyArrayLastRow(table_model.cell_editing_model );
            this.copyArrayLastRow(table_model.cell_cellBackgroundColor_model);
            this.copy3DArrayLastRow(table_model.cell_cell_font_css_model);
            this.copy3DArrayLastRow(table_model.struct_model);
        }else if(insertRowType==-2){  //insert row
            this.insertRow(table_model.data_model,p1);
            //this.cloneObjIn2DimArray(table_model.value_model,p1);
            this.insertRow(table_model.value_model,p1);
            this.state.selectCell1=[];
            this.state.selectCell2=[];
            this.insertRow(table_model.cell_align_model,p1);
            this.insertRow(table_model.cell_isThousandsFormat,p1);
            this.insertRow(table_model.cell_isPercentageFormat,p1);
            this.insertRow(table_model.cell_decimal_place,p1);
            this.insertRow(table_model.cell_border_top_model,p1);
            this.insertRow(table_model.cell_border_bottom_model,p1);
            this.insertRow(table_model.cell_border_left_model,p1);
            this.insertRow(table_model.cell_border_right_model,p1);
            this.insertRow(table_model.cell_addFilter_bright_model,p1);
            this.insertRow(table_model.cell_editing_model,p1);
            this.insertRow(table_model.cell_cellBackgroundColor_model,p1);
            this.insertRow_3D(table_model.cell_cell_font_css_model,p1);
            this.insertRow_3D(table_model.struct_model,p1);
            this.doWithInsertRow(table_model,p1);
        }else if(insertRowType==-3){
           // table_model.data_model.splice(p1,1);
            table_model.value_model.splice(p1,1);
            table_model.cell_align_model.splice(p1,1);
            table_model.cell_isThousandsFormat.splice(p1,1);
            table_model.cell_isPercentageFormat.splice(p1,1);
            table_model.cell_decimal_place.splice(p1,1);
            table_model.cell_border_top_model.splice(p1,1);
            table_model.cell_border_bottom_model.splice(p1,1);
            table_model.cell_border_left_model.splice(p1,1);
            table_model.cell_border_right_model.splice(p1,1);
            table_model.cell_addFilter_bright_model.splice(p1,1);
            table_model.cell_editing_model.splice(p1,1);
            table_model.cell_cellBackgroundColor_model.splice(p1,1);
            table_model.cell_cell_font_css_model.splice(p1,1);
            //table_model.struct_model.splice(p1,1);
            table_model.rowHeights.splice(p1,1);
            //this.state.selectCell1=[];
            //this.state.selectCell2=[];
            this.doWithDelRow(p1,table_model);
        }

        //行高数据的处理

        if(insertRowType==-1) {
            table_model.rowHeights[table_model.rowHeights.length]=table_model.rowHeights[0];
        }else if(insertRowType==-2){
            table_model.rowHeights.splice(p1,0,table_model.rowHeights[0]);
        }else if(insertRowType==-3){
           // table_model.rowHeights.splice(p1,1);
        }

        if(insertRowType==-2 || insertRowType==-3){
            this.clearCssFilter(table_model);
        }
        return table_model;
    }

    addOrDelCol=(insertType)=>{
        //复制一个history 元素，改变这个元素相关属性
        const history = this.state.history_record;
        const current =history.slice(history.length - 1)
        const table_model = current[0];
        insertType=insertType|| -1;

        let p1=-1;  //选择的位置
        let p2=-1;
        if(this.state.selectCell1.length==2){
            p1=this.state.selectCell1[1];
        }
        if(this.state.selectCell2.length==2){
            p2=this.state.selectCell2[1];
        }
        //如果是删除或者插入  -3是删除 -2是当前位置插入
        if(insertType==-3 || insertType==-2){
            if (p1==-1){
                alert("请选择一行再执行相关操作")
                return -1;}
            if(p2!=-1  && p1!=p2){
                alert("仅能选择一行再执行相关操作")
                return -1;
            }
            if(p1===0){
                alert("首列不能进行删除或插入")
                return -1;
            }
            if(this.hasEditInput()==true){
                alert("当前正在输入，无法插入或者删除列")
                return -1;
            }
        }

        let newTable_model=null;
        if(insertType==-1){
            let r=this.appendColInModel(table_model);
            newTable_model=r;
        }else if(insertType==-3){
            newTable_model=this.delColInModel(table_model,p1);
            this.clearSelectCell();
        }else if(insertType==-2){
            newTable_model=this.insertColInModel(table_model,p1);
            this.clearSelectCell();
        }
        this.setState({
            history_record: history.concat(newTable_model),
        });
    }

    appendColInModel=(table_model)=>{
        table_model.data_model=this.copyArrayLastCol(table_model.data_model);
        //table_model.value_model=this.cloneObjToLastCol(table_model.value_model)
        table_model.value_model=this.copyArrayLastCol(table_model.value_model);
        table_model.cell_align_model=this.copyArrayLastCol(table_model.cell_align_model);
        table_model.cell_isThousandsFormat=this.copyArrayLastCol(table_model.cell_isThousandsFormat);
        table_model.cell_isPercentageFormat=this.copyArrayLastCol(table_model.cell_isPercentageFormat);
        table_model.cell_decimal_place=this.copyArrayLastCol(table_model.cell_decimal_place);

        table_model.cell_border_top_model=this.copyArrayLastCol(table_model.cell_border_top_model);
        table_model.cell_border_bottom_model=this.copyArrayLastCol(table_model.cell_border_bottom_model);
        table_model.cell_border_left_model=this.copyArrayLastCol(table_model.cell_border_left_model);
        table_model.cell_border_right_model=this.copyArrayLastCol(table_model.cell_border_right_model);
        table_model.cell_addFilter_bright_model=this.copyArrayLastCol(table_model.cell_addFilter_bright_model);
        table_model.cell_editing_model=this.copyArrayLastCol(table_model.cell_editing_model);
        table_model.cell_cellBackgroundColor_model=this.copyArrayLastCol(table_model.cell_cellBackgroundColor_model);
        table_model.cell_cell_font_css_model=this.copyArrayLastCol(table_model.cell_cell_font_css_model);
        table_model.cell_cell_font_css_model=this.copy3DArrayLastCol(table_model.cell_cell_font_css_model);
        table_model.struct_model=this.copy3DArrayLastCol(table_model.struct_model);
        table_model.colWidths=[...table_model.colWidths,table_model.colWidths[0]];
        return table_model;
    }

    delColInModel=(table_model,p)=>{
        //table_model.data_model=this.deleteCol(table_model.data_model,p);
        table_model.value_model=this.deleteCol(table_model.value_model,p);
        table_model.cell_align_model=this.deleteCol(table_model.cell_align_model,p);
        table_model.cell_isThousandsFormat=this.deleteCol(table_model.cell_isThousandsFormat,p);
        table_model.cell_isPercentageFormat=this.deleteCol(table_model.cell_isPercentageFormat,p);
        table_model.cell_decimal_place=this.deleteCol(table_model.cell_decimal_place,p);

        table_model.cell_border_top_model=this.deleteCol(table_model.cell_border_top_model,p);
        table_model.cell_border_bottom_model=this.deleteCol(table_model.cell_border_bottom_model,p);
        table_model.cell_border_left_model=this.deleteCol(table_model.cell_border_left_model,p);
        table_model.cell_border_right_model=this.deleteCol(table_model.cell_border_right_model,p);
        table_model.cell_addFilter_bright_model=this.deleteCol(table_model.cell_addFilter_bright_model,p);
        table_model.cell_editing_model=this.deleteCol(table_model.cell_editing_model,p);
        table_model.cell_cellBackgroundColor_model=this.deleteCol(table_model.cell_cellBackgroundColor_model,p);
        table_model.cell_cell_font_css_model=this.deleteCol(table_model.cell_cell_font_css_model,p);
        table_model.colWidths.splice(p,1);  //列宽数组中删除
        this.doWithDelCol(table_model,p);
        return table_model;
    }


    insertColInModel=(table_model,p)=>{
        table_model.data_model=this.insertCol(table_model.data_model,p);
        //table_model.value_model= this.insertcolToValeMode(table_model.value_model,p);
        table_model.value_model=this.insertCol(table_model.value_model,p);
        table_model.cell_align_model=this.insertCol(table_model.cell_align_model,p);
        table_model.cell_isThousandsFormat=this.insertCol(table_model.cell_isThousandsFormat,p);
        table_model.cell_isPercentageFormat=this.insertCol(table_model.cell_isPercentageFormat,p);
        table_model.cell_decimal_place=this.insertCol(table_model.cell_decimal_place,p);

        table_model.cell_border_top_model=this.insertCol(table_model.cell_border_top_model,p);
        table_model.cell_border_bottom_model=this.insertCol(table_model.cell_border_bottom_model,p);
        table_model.cell_border_left_model=this.insertCol(table_model.cell_border_left_model,p);
        table_model.cell_border_right_model=this.insertCol(table_model.cell_border_right_model,p);
        table_model.cell_addFilter_bright_model=this.insertCol(table_model.cell_addFilter_bright_model,p);
        table_model.cell_editing_model=this.insertCol(table_model.cell_editing_model,p);
        table_model.cell_cellBackgroundColor_model=this.insertCol(table_model.cell_cellBackgroundColor_model,p);
        table_model.cell_cell_font_css_model=this.insertColIn3DArray(table_model.cell_cell_font_css_model,p);
        table_model.struct_model=this.insertColIn3DArray(table_model.struct_model,p);
        this.doWithInsertCol(table_model,p);
        table_model.colWidths.splice(p,0,table_model.colWidths[0]);
        return table_model;
    }
    //direction  1 左对齐  2 中对齐 3 右对齐
    align(direction){
        const history = this.state.history_record;
        const current =history.slice(history.length - 1)
        const table_model = current[0];

        //找出所有选择的单元格 ， 放入一个集合 ，对集合进行遍历
        let range= this.selectRange();
        if(range==-1){ return;}
        let row_start=range[0];
        let row_end= range[1];
        let col_start= range[2];
        let col_end= range[3];
        //this.clearCssFilter(current_table_model);
        for (let i=row_start;i<=row_end;i++)
        {
            for (let j=col_start;j<=col_end;j++){
                table_model.cell_align_model[i][j]=direction;  //范围内全部家filter
            }
        }
        //setState 即可引发渲染
        this.setState({
            history_record: this.state.history_record,
        });
    }



    //hidenData  显示隐藏数据 v=1 是隐藏数据  0 是显示数据
    hidenData(v){
        const history = this.state.history_record;
        const current =history.slice(history.length - 1)
        const table_model = current[0];

        //找出所有选择的单元格 ， 放入一个集合 ，对集合进行遍历
        let range= this.selectRange();
        if(range==-1){ return;}  //啥都没有 不处理
        let row_start=range[0];
        let row_end= range[1];
        let col_start= range[2];
        let col_end= range[3];
        //this.clearCssFilter(current_table_model);
        for (let i=row_start;i<=row_end;i++)
        {
            for (let j=col_start;j<=col_end;j++){
                table_model.cell_hiden_data_model[i][j]=v;  //范围内全部家filter
            }
        }
        //setState 即可引发渲染
        this.setState({
            history_record: this.state.history_record,
        });
    }

//加粗
    editFont(type){
        const history = this.state.history_record;
        const current =history.slice(history.length - 1)
        const table_model = current[0];

        //找出所有选择的单元格 ， 放入一个集合 ，对集合进行遍历
        let range= this.selectRange();
        if(range==-1){ return;}
        let row_start=range[0];
        let row_end= range[1];
        let col_start= range[2];
        let col_end= range[3];
        //this.clearCssFilter(current_table_model);
        for (let i=row_start;i<=row_end;i++)
        {
            for (let j=col_start;j<=col_end;j++){
                //反向处理
                if(type==2){   //
                    if(table_model.cell_cell_font_css_model[i][j][2]=='font-weight_bold'){
                        table_model.cell_cell_font_css_model[i][j][2] ='font-weight_normal' //范围内全部
                    }else{
                    table_model.cell_cell_font_css_model[i][j][2] ='font-weight_bold' //范围内全部
                    }
                }else if(type==3){
                    if(table_model.cell_cell_font_css_model[i][j][3]=='font-sytle_italic'){
                        table_model.cell_cell_font_css_model[i][j][3] ='font-sytle_normal' //范围内全部
                    }else{
                        table_model.cell_cell_font_css_model[i][j][3] ='font-sytle_italic' //范围内全部
                    }
                }else if(type==4){
                    if(table_model.cell_cell_font_css_model[i][j][4]=='underline'){
                        table_model.cell_cell_font_css_model[i][j][4] ='none' //范围内全部
                    }else{
                        table_model.cell_cell_font_css_model[i][j][4] ='underline' //范围内全部
                    }
                }else if(type==101){
                    table_model.cell_cell_font_css_model[i][j][0] ='microYH' //范围内全部
                }else if(type==102){
                    table_model.cell_cell_font_css_model[i][j][0] ='st' //范围内全部
                }else if(type==103){
                    table_model.cell_cell_font_css_model[i][j][0] ='xst' //范围内全部
                }else if(type==104){
                    table_model.cell_cell_font_css_model[i][j][0] ='ht' //范围内全部
                }else if(type==105){
                    table_model.cell_cell_font_css_model[i][j][0] ='fs' //范围内全部
                }else if(type==106){
                    table_model.cell_cell_font_css_model[i][j][0] ='kt' //范围内全部
                }else if(type==201){
                    table_model.cell_cell_font_css_model[i][j][1] ='medium' //范围内全部
                }else if(type==202){
                    table_model.cell_cell_font_css_model[i][j][1] ='small' //范围内全部
                }else if(type==203){
                    table_model.cell_cell_font_css_model[i][j][1] ='large' //范围内全部
                }else if(type==204){
                    table_model.cell_cell_font_css_model[i][j][1] ='x-small' //范围内全部
                }else if(type==205){
                    table_model.cell_cell_font_css_model[i][j][1] ='x-large' //范围内全部
                }else if(type==206){
                    table_model.cell_cell_font_css_model[i][j][1] ='xx-large' //范围内全部
                }
            }
        }
        //setState 即可引发渲染
        this.setState({
            history_record: this.state.history_record,
        });
    }

//是千分位
    isThousandsFormat=()=>{
        const history = this.state.history_record;
        const current =history.slice(history.length - 1)
        const table_model = current[0];
        //找出所有选择的单元格 ， 放入一个集合 ，对集合进行遍历
        let range= this.selectRange();
        if(range==-1){ return;}
        let row_start=range[0];
        let row_end= range[1];
        let col_start= range[2];
        let col_end= range[3];
        //this.clearCssFilter(current_table_model);
        for (let i=row_start;i<=row_end;i++)
        {
            for (let j=col_start;j<=col_end;j++){
                table_model.cell_isThousandsFormat[i][j]=1;  //范围内全部家filter
                table_model.cell_isPercentageFormat[i][j]=0;  //范围内全部家filter
            }
        }
        //setState 即可引发渲染
        this.setState({
            history_record: this.state.history_record,
        });
    }

    //百分位
    isPercentageFormat=()=>{
        const history = this.state.history_record;
        const current =history.slice(history.length - 1)
        const table_model = current[0];
        //找出所有选择的单元格 ， 放入一个集合 ，对集合进行遍历
        let range= this.selectRange();
        if(range==-1){ return;}
        let row_start=range[0];
        let row_end= range[1];
        let col_start= range[2];
        let col_end= range[3];
        //this.clearCssFilter(current_table_model);
        for (let i=row_start;i<=row_end;i++)
        {
            for (let j=col_start;j<=col_end;j++){
                table_model.cell_isPercentageFormat[i][j]=1;  //范围内全部家filter
                table_model.cell_isThousandsFormat[i][j]=0;
            }
        }
        //setState 即可引发渲染
        this.setState({
            history_record: this.state.history_record,
        });
    }

    setDecimalPlaces=(p)=>{
      //todo setDecimalPlaces
        const history = this.state.history_record;
        const current =history.slice(history.length - 1)
        const table_model = current[0];
        //找出所有选择的单元格 ， 放入一个集合 ，对集合进行遍历
        let range= this.selectRange();
        if(range==-1){ return;}
        let row_start=range[0];
        let row_end= range[1];
        let col_start= range[2];
        let col_end= range[3];
        //this.clearCssFilter(current_table_model);
        for (let i=row_start;i<=row_end;i++)
        {
            for (let j=col_start;j<=col_end;j++){
                // table_model.cell_isThousandsFormat[i][j]=1;  //范围内全部家filter
                // table_model.cell_isPercentageFormat[i][j]=0;  //范围内全部家filter
                table_model.cell_decimal_place[i][j]=p;
            }
        }
        //setState 即可引发渲染
        this.setState({
            history_record: this.state.history_record,
        });
    }

//todo clearNumFormat



    clearNumFormat=()=>{
        const history = this.state.history_record;
        const current =history.slice(history.length - 1)
        const table_model = current[0];
        //找出所有选择的单元格 ， 放入一个集合 ，对集合进行遍历
        let range= this.selectRange();
        if(range==-1){ return;}
        let row_start=range[0];
        let row_end= range[1];
        let col_start= range[2];
        let col_end= range[3];
        //this.clearCssFilter(current_table_model);
        for (let i=row_start;i<=row_end;i++)
        {
            for (let j=col_start;j<=col_end;j++){
                table_model.cell_isThousandsFormat[i][j]=0;  //范围内全部家filter
                table_model.cell_isPercentageFormat[i][j]=0;  //范围内全部家filter
                table_model.cell_decimal_place[i][j]=-1;  //范围内全部家filter
            }
        }
        //setState 即可引发渲染
        this.setState({
            history_record: this.state.history_record,
        });
    }

    //返回选择范围坐标   如果返回-1 则表示用户没有选择  正常返回是数组[开始行，结束行，开始列，结束列]
    selectRange(){
        let row_start= -1;
        let row_end=  -1;
        let col_start=  -1;
        let col_end=  -1;
      if(this.state.selectCell1.length!=2){
          alert("请选择单元格范围");
          return -1;
      }
      if(this.state.selectCell2.length==2){  //用户选择了单元格范围
           row_start= this.state.selectCell1[0]<this.state.selectCell2[0] ? this.state.selectCell1[0] :this.state.selectCell2[0];
           row_end= this.state.selectCell1[0]>this.state.selectCell2[0] ? this.state.selectCell1[0] :this.state.selectCell2[0];
           col_start= this.state.selectCell1[1]<this.state.selectCell2[1] ? this.state.selectCell1[1] :this.state.selectCell2[1];
           col_end= this.state.selectCell1[1]>this.state.selectCell2[1] ? this.state.selectCell1[1] :this.state.selectCell2[1];
           return [row_start,row_end,col_start,col_end]
      }else{   //用户仅仅点击了一次 选择了一个单元格
           return [this.state.selectCell1[0],this.state.selectCell1[0],this.state.selectCell1[1],this.state.selectCell1[1]];
      }
    }

    isAddCell=(rowNo,colNo)=>{
    }


    getRows(rowData,rowValue,rowIsThousandsFormat,rowIsPercentageFormat,rowDecimalPlace,row_struct_model,rowHeight,rowAligns,rowborder_tops,rowborder_bottoms,rowborder_lefts,rowborder_rights,
            rowaddFilter_brights,rowcellBackgroundColors,rowcell_font_cssArray,rowCell_editing_mode,colNum, rowNo,rowIndex) {
        let rowDataTest=rowData.slice();
       // let row_struct_model_data=row_struct_model.slice();
        return <CommRow colNum={colNum}
                        rowNo={rowNo}
                        key={"dataRow" + rowNo + "_" + colNum}
                        rowData={rowDataTest}
                        rowValue={rowValue}
                        rowIsThousandsFormat={rowIsThousandsFormat}
                        rowIsPercentageFormat={rowIsPercentageFormat}
                        rowDecimalPlace={rowDecimalPlace}

                        row_struct_model={row_struct_model}
                        rowHeight={rowHeight}
                        rowAligns={rowAligns}
                        rowborder_tops={rowborder_tops}
                        rowborder_bottoms={rowborder_bottoms}
                        rowborder_lefts={rowborder_lefts}
                        rowborder_rights={rowborder_rights}
                        rowaddFilter_brights={rowaddFilter_brights}
                        rowcellBackgroundColors={rowcellBackgroundColors}
                        rowcell_font_cssArray={rowcell_font_cssArray}
                        rowCell_editing_mode={rowCell_editing_mode}
                        /*isSelect_cells={this.state.cellSelectStates[rowIndex]}*/
                        handleCellSelect={(e,i,j)=> this.handleCellSelect(e,i,j)}
                        handleCellDoubleClick={(e,i,j)=> this.handleCellDoubleClick(e,i,j)}
                        handleRowHeadMouseDown={(e,i)=> this.handleRowHeadMouseDown(e,rowNo)}
                        isAddCell={(rowNo,colNo)=> this.isAddCell(rowNo,colNo)}
                        handleChangedCell={(i,j,value)=> this.handleChangedCell(i,j,value)}
                        executeFormula={this.executeFormula}
        />
    }

    getTableHeads(colNum,colWidths){
        return < TableHead colNum={colNum}
                           colWidths={colWidths}
                           key={"TableHeadRow" + "_" + colNum}
                           handleCellMouseDown={(e,i)=> this.handleCellMouseDown(e,i)}
                           handleCellMouseUp={(e,i)=> this.handleCellMouseUp(e,i)}
                           handleTableHeadMouseUp={(e)=> this.handleTableHeadMouseUp(e)}
       />
    }

    clearCssFilter(current_table_model){
        for(let  i=0;i<current_table_model.cell_addFilter_bright_model.length;i++){
            for (let j=0;j<current_table_model.cell_addFilter_bright_model[i].length;j++){
                current_table_model.cell_addFilter_bright_model[i][j]=0;  //范围内全部家filter
            }
        }
    }

    // twoDimArray 是个二维数组，本方法是在每行末追加一个元素
    copyArrayLastCol(twoDimArray){
        let r=twoDimArray.map (item => { // item为数组的元素
            item=[...item,item[0]]
            return item; // 返回一个处理过的新数组
        })
    return r;  //返回一个新的数组
    }

    copy3DArrayLastCol=(threeDimArray)=>{
        let r=threeDimArray.map(item => { // item为数组的元素
        //let   n=[...item[item.length-1]]
        let   n=[...item[0]]
           item=[...item,n]
            return item; // 返回一个处理过的新数组
        })
        return r;  //返回一个新的数组
    }


    cloneObjToLastCol=(array_2)=>{
        let r=array_2.map(item => { // item为数组的元素
            //let   n=[...item[item.length-1]]
            //let   n=[...item[0]]
            //本身是个数组item
            let arrCopy = [];
            for (let i = 0; i < item.length; i++) {
                arrCopy.push(Object.assign({},item[i]))
            }

            let n=Object.assign({},item[0]);
            item=[...arrCopy,n]
            return item; // 返回一个处理过的新数组
        })
        return r;  //返回一个新的数组
    }


    insertcolToValeMode=(array_2,p)=>{
        let r=array_2.map(item => { // item为数组的元素   遍历每一行
            //let   n=[...item[item.length-1]]
            //let   n=[...item[0]]
            //本身是个数组item
            let arrCopy = [];
            for (let i = 0; i < p; i++) {
                arrCopy.push(Object.assign({},item[i]))
            }
            let n=Object.assign({},item[0]);
            arrCopy.push(n);
            for (let i = p; i < item.length; i++) {
                arrCopy.push(Object.assign({},item[i]))
            }
            item=[...arrCopy]
            return item; // 返回一个处理过的新数组
        })
        return r;  //返回一个新的数组
    }





    copyArrayLastRow(twoDimArray){
        //let r=twoDimArray[twoDimArray.length-1];
        let r=twoDimArray[0];
         let newRowData = [...r];
        twoDimArray[twoDimArray.length]=newRowData;
    }

    //这个方法只是修改原来数组  （就是说 原来数据是引用的）新追加一组数据
    copy3DArrayLastRow(treeDimArray){
        //let r=treeDimArray[treeDimArray.length-1];  //r是二维数组
        let r=treeDimArray[0];  //r是二维数组
        //let newRowData = [[...r[0]]];
        let newRowData=r.map(item => { // item为数组的元素
            item=[...item]
            return item; // 返回一个处理过的新数组
        })
        treeDimArray[treeDimArray.length]=newRowData;
    }

    //clone objet and append last row in array
    //position=-1  则追加到最后
    cloneObjIn2DimArray=(array_2,position)=>{
        let r=array_2[0];  //
        let newRowData=r.map(item => { // item为数组的元素
            item=Object.assign({},item)
            return item; // 返回一个处理过的新数组
        })
        if(position>=0){  //插入
            array_2.splice(position,0,newRowData);
        }else{  //追加
            array_2[array_2.length]=newRowData;
        }
    }



    //复制最后一行，然后插入到指定位置
    insertRow(twoDimArray,p){
        //let r=twoDimArray[twoDimArray.length-1];
        let r=twoDimArray[0];
        let newRowData = [...r];
        twoDimArray.splice(p,0,newRowData);
    }

    //复制最后一行，然后插入到指定位置
    insertRow_3D(threeDimArray,p){
        let r=threeDimArray[0];
        let newRowData=r.map(item => { // item为数组的元素
            item=[...item]
            return item; // 返回一个处理过的新数组
        })
        threeDimArray.splice(p,0,newRowData);
    }


    // twoDimArray 是个二维数组，
     deleteCol(twoDimArray,p){
        let r=twoDimArray.map(item => { // item为数组的元素
            item.splice(p,1);   //splice 方法会改变原始数组
            return item; // 返回一个处理过的新数组
        })
        return r;
    }

    // twoDimArray 是个二维数组，
    insertCol(twoDimArray,p){
        let r=twoDimArray.map(item => { // item为数组的元素
            let newItem=item.slice();
            newItem.splice(p,0,item[0]);   //splice 方法会改变原始数组
            return newItem; // 返回一个处理过的新数组
        })
        return r;
    }

    // threeDimArray 是个三维数组，
    insertColIn3DArray(threeDimArray,p){
        let r=threeDimArray.map(item => { // item为数组的元素
            let n=[...item[0]];
            item.splice(p,0,n);   //splice 方法会改变原始数组
            return item; // 返回一个处理过的新数组
        })
        return r;
    }

    modifyBorderStyle=(t)=>{
        const history = this.state.history_record;
        const current =history.slice(history.length - 1)
        const table_model = current[0];

        //找出所有选择的单元格 ， 放入一个集合 ，对集合进行遍历
        let range= this.selectRange();
        if(range==-1){ return;}
        let row_start=range[0];
        let row_end= range[1];
        let col_start= range[2];
        let col_end= range[3];
        //this.clearCssFilter(current_table_model);
        for (let i=row_start;i<=row_end;i++)
        {
            for (let j=col_start;j<=col_end;j++){
                if(t==0){
                    table_model.cell_border_top_model[i][j] =0
                    table_model.cell_border_bottom_model[i][j] =0
                    table_model.cell_border_left_model[i][j] =0
                    table_model.cell_border_right_model[i][j] =0
                }else if (t==2){   //全实线
                    table_model.cell_border_top_model[i][j] =2
                    table_model.cell_border_bottom_model[i][j] =2
                    table_model.cell_border_left_model[i][j] =2
                    table_model.cell_border_right_model[i][j] =2
                }else if (t==3){  //仅仅上边线
                    table_model.cell_border_top_model[i][j] =2
                    // table_model.cell_border_bottom_model[i][j] =0
                    // table_model.cell_border_left_model[i][j] =0
                    // table_model.cell_border_right_model[i][j] =0
                }else if (t==4){  // 仅仅右边线
                    // table_model.cell_border_top_model[i][j] =0
                    // table_model.cell_border_bottom_model[i][j] =0
                    // table_model.cell_border_left_model[i][j] =0
                    table_model.cell_border_right_model[i][j] =2
                }else if (t==5){    //仅底边线
                    // table_model.cell_border_top_model[i][j] =0
                    table_model.cell_border_bottom_model[i][j] =2
                    // table_model.cell_border_left_model[i][j] =0
                    // table_model.cell_border_right_model[i][j] =0
                }else if (t==6){ //仅仅左边线
                    // table_model.cell_border_top_model[i][j] =0
                    // table_model.cell_border_bottom_model[i][j] =0
                    table_model.cell_border_left_model[i][j] =2
                    // table_model.cell_border_right_model[i][j] =0
                }else if (t==7){
                    //todo
                }else if (t==8){
                    //todo
                }
            }
        }
        //setState 即可引发渲染
        this.setState({
            history_record: this.state.history_record,
        });
    }





    clearSelectCell(){
        this.state.selectCell1=[];
        this.state.selectCell2=[];
    }

    //合并单元格
    mergeCells=()=>{
        const history = this.state.history_record;
        const current =history.slice(history.length - 1)
        const table_model = current[0];

        //找出所有选择的单元格 ， 放入一个集合 ，对集合进行遍历
        let range= this.selectRange();
        if(range==-1){ return;}
        let row_start=range[0];
        let row_end= range[1];
        let col_start= range[2];
        let col_end= range[3];

        if(row_start==row_end  && col_start==col_end){return}

        let _spanRow=row_end-row_start+1;
        let _spanCol=col_end-col_start+1;
        //this.clearCssFilter(current_table_model);
        for (let i=row_start;i<=row_end;i++)
        {
            for (let j=col_start;j<=col_end;j++){
                table_model.data_model[i][j]=0;  //范围内全部家filter
                table_model.struct_model[i][j][0]=0;  //跨行 垂直方向
                table_model.struct_model[i][j][1]=0;    //跨列  水平方向
                //table_model.struct_model[i][j]=[0,0]  这个写法更简单?
            }
        }
        table_model.data_model[row_start][col_start]=1;
        table_model.struct_model[row_start][col_start][0]=_spanRow;
        table_model.struct_model[row_start][col_start][1]=_spanCol;

        //删除在选定范围内的全部合并单元信息  建立新的合并单元信息
        ////es6遍历的时候 如何删除？
        //以下是错误做法
        // this.state.mergeCellArray.forEach((item,index)=>{
        //     //包含在选中区当中的合并单元格记录全部清除掉
        //    if(item[0]>=row_start && row_end>=item[2] && item[1]>=col_start && col_end >= item[3]){
        //        this.state.mergeCellArray.splice(index,1);
        //    }
        // })
        this.state.mergeCellArray=
        this.state.mergeCellArray.filter((item)=>{
            if(item[0]>=row_start && row_end>=item[2] && item[1]>=col_start && col_end >= item[3]){
                return false;  //需要过滤吊顶
            }else{
                return true;
            }
        });//过滤不改变原来的数组
        this.state.mergeCellArray.push([row_start,col_start,row_end,col_end])
        //setState 即可引发渲染
        this.setState({
            history_record: this.state.history_record,
        });
    }

    splitCells=()=>{
        const history = this.state.history_record;
        const current =history.slice(history.length - 1)
        const table_model = current[0];

        //找出所有选择的单元格 ， 放入一个集合 ，对集合进行遍历
        let range= this.selectRange();
        if(range==-1){ return;}
        let row_start=range[0];
        let row_end= range[1];
        let col_start= range[2];
        let col_end= range[3];


        let v=this.adjustSelectCell2(table_model.struct_model,[row_end,col_end]);  //需要调整的值
        if(v[0]>1){
            row_end=row_end+v[0]-1;
        }
        if(v[1]>1){
            col_end=col_end+v[1]-1;
        }


        for (let i=row_start;i<=row_end;i++)
        {
            for (let j=col_start;j<=col_end;j++){
                table_model.data_model[i][j]=1;
                table_model.struct_model[i][j]=[1,1]
            }
        }
        //删除在选定范围内的全部合并单元信息  建立新的合并单元信息
        ////es6遍历的时候 如何删除？


        // this.state.mergeCellArray=
        //     this.state.mergeCellArray.filter((item)=>{
        //         if(item[0]>=row_start && row_end>=item[2] && item[1]>=col_start && col_end >= item[3]){
        //             return false;  //需要过滤吊顶
        //         }else{
        //             return true;
        //         }
        //     });//过滤好像不改变原来的数组


        let _mergeCellArray=
            this.state.mergeCellArray.filter((item)=>{
                if(item[0]>=row_start && row_end>=item[2] && item[1]>=col_start && col_end >= item[3]){
                    return false;  //需要过滤吊顶
                }else{
                    return true;
                }
            });//过滤好像不改变原来的数组


        //setState 即可引发渲染
        this.setState({
            history_record: this.state.history_record,
            mergeCellArray:_mergeCellArray
        });
    }

//是否选择了单元格
    hasSelectedCell=()=>{
        if(this.state.selectCell1.length!=2){
            return -1;
        }else{
            return  1;
        }
    }
    //获取选择单元格的值
    getSelectCellValue=()=>{
        if(this.state.selectCell1.length!=2){
            return "";
        }else{
            if(this.state.formulaText==undefined ||
                this.state.formulaText==null){
                return ""
            }else{
                return  this.state.formulaText;
            }
        }
    }


    saveFormulaToCell=(formulaTxt)=>{
        if(this.state.selectCell1.length!=2){
            return -1;
        }else{
            //设置单元格
            const history = this.state.history_record;
            const current =history.slice(history.length - 1)
            const table_model = current[0];
            let i=this.state.selectCell1[0];
            let j=this.state.selectCell1[1]
            if(formulaTxt==undefined || formulaTxt==null  ||  formulaTxt==""){
                table_model.value_model[i][j]="";
            }else{
                table_model.value_model[i][j]="@"+formulaTxt;
            }
            this.setState({
                history_record: this.state.history_record,
            });
        }
    }

    adjustSelectCell2=(struct_model,selectCell2)=>{
            let c=struct_model[selectCell2[0]][selectCell2[1]];
            return [c[0],c[1]];  //跨行 跨列数
    }

//跨第P行的合并单元格,返回结果为数组[r,i]，其中 r、i 分别又是个数组
    getMergeCell=(p)=>{
            let i=[];
            let r=[];
            r=this.state.mergeCellArray.filter((item,index)=>{
                if(item[2]>=p  && p>=item[0]){
                    i.push(index);
                    return true;
                }else{
                    return false;
                }
            });//过滤好像不改变原来的数组
        return [r,i];
    }

    //跨第P行的合并单元格(第一行不算),返回结果为数组[r,i]，其中 r、i 分别又是个数组
    getMergeCell_2=(p)=>{
        let i=[];
        let r=[];
        r=this.state.mergeCellArray.filter((item,index)=>{
            if(item[2]>=p  && p>item[0]){
                i.push(index);
                return true;
            }else{
                return false;
            }
        });//过滤不改变原来的数组
        return [r,i];
    }




    //跨第P列的合并单元格,返回结果为数组[r,i]，其中 r、i 分别又是个数组
    getMergeCellWithCrossCol=(p)=>{
        let i=[];
        let r=[];
        r=this.state.mergeCellArray.filter((item,index)=>{
            if(item[3]>=p  && p>=item[1]){
                i.push(index);
                return true;
            }else{
                return false;
            }
        });//过滤好像不改变原来的数组
        return [r,i];
    }



    //跨第P列的合并单元格,  不包括第一列 返回结果为数组[r,i]，其中 r、i 分别又是个数组
  getMergeCellWithCrossCol_2=(p)=>{
      let i=[];
      let r=[];
      r=this.state.mergeCellArray.filter((item,index)=>{
          if(item[3]>=p  && p>item[1]){
              i.push(index);
              return true;
          }else{
              return false;
          }
      });//过滤好像不改变原来的数组
      return [r,i];
    }










    //跨第P行下部的 合并单元格
    getMergeCellAtLower=(p)=>{
        let i=[];
        let r=[];
        r=this.state.mergeCellArray.filter((item,index)=>{
            if(item[0]>p){
                i.push(index);
                return true;
            }else{
                return false;
            }
        });//过滤好像不改变原来的数组
        return [r,i];
    }








    //跨第P行下部的 合并单元格  含有插入行的
    getMergeCellAtLower_2=(p)=>{
        let i=[];
        let r=[];
        r=this.state.mergeCellArray.filter((item,index)=>{
            if(item[0]>=p){
                i.push(index);
                return true;
            }else{
                return false;
            }
        });//过滤不改变原来的数组
        return [r,i];
    }




    //位于p右侧的合并单元格
    getMergeCellAtRight=(p)=>{
        let i=[];
        let r=[];
        r=this.state.mergeCellArray.filter((item,index)=>{
            if(item[1]>p){
                i.push(index);
                return true;
            }else{
                return false;
            }
        });//过滤好像不改变原来的数组
        return [r,i];
    }



    //位于p右侧的合并单元格  含有插入列
    getMergeCellAtRight_2=(p)=>{
        let i=[];
        let r=[];
        r=this.state.mergeCellArray.filter((item,index)=>{
            if(item[1]>=p){
                i.push(index);
                return true;
            }else{
                return false;
            }
        });//过滤好像不改变原来的数组
        return [r,i];
    }
    //以P行开头的合并单元格,返回结果为数组[r,i]，其中 r、i 分别又是个数组
    getMergeCellAtFirstRow=(p)=>{
        let i=[];
        let r=[];
        r=this.state.mergeCellArray.filter((item,index)=>{
            if( p==item[0]){
                i.push(index);
                return true;
            }else{
                return false;
            }
        });//过滤好像不改变原来的数组
        return [r,i];
    }

    //处理删除行的情况(合并单元格)
    doWithDelRow=(p,table_model)=>{
            let r=this.getMergeCell(p);
            let lowerPart=this.getMergeCellAtLower(p);

        var arr = Object.keys(r[0]);
        var arr_l = Object.keys(lowerPart[0]);
        //alert(arr.length == 0);//true 即为空对象

        if(arr_l.length > 0) {
            lowerPart[0].forEach((item, index) => {
                let _position=lowerPart[1][index];
                let t = this.state.mergeCellArray[_position];
                t = [t[0] - 1, t[1], t[2] - 1, t[3]];
                this.state.mergeCellArray[_position]=t;
            });
        }

         if(arr.length > 0){
          r[0].forEach((item, index)=>{
              let y=item[0];
              let x=item[1];
              let c=table_model.struct_model[y][x];
              if(item[0]==p){  //第一行
                  if(item[0]==item[2]){   //就一行数据
                    //struct_model、data_model、mergeCellArray[index]会被删除
                    //   this.state.mergeCellArray=
                    //       this.state.mergeCellArray.filter((element)=>{
                    //           if(element[0]==item[0] && element[1]==item[1]&& element[2]==item[2]&& element[3]==item[3]){
                    //               return false;  //需要过滤吊顶
                    //           }else{
                    //               return true;
                    //           }
                    //       });//过滤好像不改变原来的数组
                      //标记一下 后面对这类数据进行删除
                      let _position=r[1][index];
                      this.state.mergeCellArray[_position]=[0,0,0,0];
                  }else{
                      table_model.struct_model[y+1][x][0]=c[0]-1;
                      table_model.struct_model[y+1][x][1]=c[1];
                      table_model.data_model[y+1][x]=1;
                      // 调整设计的mergecells中相应合并区记录的数据  首先是找到这个记录
                      let _position=r[1][index];
                      let t=this.state.mergeCellArray[_position];
                      t=[t[0],t[1],t[2]-1,t[3]];
                      this.state.mergeCellArray[_position]=t;
                  }
              }else if(item[2]>=p){  //最后一行
                  table_model.struct_model[y][x][0]=c[0]-1;
                  // 调整设计的mergecells中相应合并区记录的数据  首先是找到这个记录
                  let _position=r[1][index];
                  let t=this.state.mergeCellArray[_position];
                  this.state.mergeCellArray[_position]=[t[0],t[1],t[2]-1,t[3]];
              }
          });
         };

        //结果删除行的处理  可能有的合并单元格已不是合并单元格，这个时候，需要从mergercell删除
        if(this.state.mergeCellArray.length>0){
            this.state.mergeCellArray=
                this.state.mergeCellArray.filter((item)=>{
                    if(item[0]==item[2] && item[1]==item[3]){
                        return false;  //需要过滤吊顶
                    }else{
                        return true;
                    }
                });//过滤不改变原来的数组
        }
        //调整后，才能去掉本行  这里(p==x)
        table_model.data_model.splice(p,1);
        table_model.struct_model.splice(p,1);
    }






//插入行
    doWithInsertRow=(table_model,p)=>{
        let r=this.getMergeCell_2(p);
        let lowerPart=this.getMergeCellAtLower_2(p);  // 插入行在合并单元格以前
        var arr = Object.keys(r[0]);
        var arr_l = Object.keys(lowerPart[0]);
        if(arr_l.length > 0){   //合并单元格在插入行之后
            lowerPart[0].forEach((item, index) => {
                let _position=lowerPart[1][index];
                let t = this.state.mergeCellArray[_position];
                t = [t[0] + 1, t[1], t[2] + 1, t[3]];
                this.state.mergeCellArray[_position]=t;
            });
        }
        if(arr.length > 0){
            r[0].forEach((item, index) => {
                let _position=r[1][index];
                let t = this.state.mergeCellArray[_position];
                //修正struct_mode
                let c=table_model.struct_model[t[0]][t[1]];
                table_model.struct_model[t[0]][t[1]][0]=c[0]+1;
                t = [t[0], t[1], t[2] + 1, t[3]];
                this.state.mergeCellArray[_position]=t;
            });
        }

        //插入行

        // let newRow=table_model.data_model[0];
        // let newRowData = [...newRow];


        let _row_struct_model=table_model.struct_model[p];  //当前行的struct_mode
        let _row_data_model=table_model.data_model[p];
        r[0].forEach((item, index) => {
            let _beginCol=item[1];
            let _endCol=item[3];
            for (let i = _beginCol; i <=_endCol; i++) {
                _row_data_model[i]=0;
                _row_struct_model[i]=[0,0];
            }
        });
    }



    //处理删除列的情况(合并单元格)
    doWithDelCol=(table_model,p)=>{
        let r=this.getMergeCellWithCrossCol(p);
        let _mergeCellAtRight=this.getMergeCellAtRight(p);

        var arr = Object.keys(r[0]);
        var arr_l = Object.keys(_mergeCellAtRight[0]);
        //alert(arr.length == 0);//true 即为空对象

        if(arr_l.length > 0) {
            _mergeCellAtRight[0].forEach((item, index) => {
                let _position=_mergeCellAtRight[1][index];
                let t = this.state.mergeCellArray[_position];
                t = [t[0], t[1]-1, t[2], t[3]-1];
                this.state.mergeCellArray[_position]=t;
            });
        }

        if(arr.length > 0){
            r[0].forEach((item, index)=>{
                let y=item[0];
                let x=item[1];
                let c=table_model.struct_model[y][x];
                if(item[1]==p){  //第一列
                    if(item[1]==item[3]){   //就一行数据
                        let _position=r[1][index];
                        this.state.mergeCellArray[_position]=[0,0,0,0];
                    }else{
                        table_model.struct_model[y][x+1][0]=c[0];
                        table_model.struct_model[y][x+1][1]=c[1]-1;
                        table_model.data_model[y][x+1]=1;
                        // 调整设计的mergecells中相应合并区记录的数据  首先是找到这个记录
                        let _position=r[1][index];
                        let t=this.state.mergeCellArray[_position];
                        t=[t[0],t[1],t[2],t[3]-1 ];
                        this.state.mergeCellArray[_position]=t;
                    }
                }else if(item[3]>=p){  //非第一列
                    table_model.struct_model[y][x][1]=c[1]-1;
                    // 调整设计的mergecells中相应合并区记录的数据  首先是找到这个记录
                    let _position=r[1][index];
                    let t=this.state.mergeCellArray[_position];
                    this.state.mergeCellArray[_position]=[t[0],t[1],t[2],t[3]-1];
                }
            });
        };

        //结果删除行的处理  可能有的合并单元格已不是合并单元格，这个时候，需要从mergercell删除
        if(this.state.mergeCellArray.length>0){
            this.state.mergeCellArray=
                this.state.mergeCellArray.filter((item)=>{
                    if(item[0]==item[2] && item[1]==item[3]){
                        return false;  //需要过滤吊顶
                    }else{
                        return true;
                    }
                });//过滤好像不改变原来的数组
        }

        table_model.data_model=this.deleteCol(table_model.data_model,p);
        table_model.struct_model=this.deleteCol(table_model.struct_model,p);
    }

    //插入列
    doWithInsertCol=(table_model,p)=>{
        let r=this.getMergeCellWithCrossCol_2(p);
        let _mergeCellAtRight=this.getMergeCellAtRight_2(p);
        let arr = Object.keys(r[0]);
        let arr_l = Object.keys(_mergeCellAtRight[0]);
        if(arr_l.length > 0) {
            _mergeCellAtRight[0].forEach((item, index) => {
                let _position=_mergeCellAtRight[1][index];
                let t = this.state.mergeCellArray[_position];
                t = [t[0], t[1]+1, t[2], t[3]+1];
                this.state.mergeCellArray[_position]=t;
            });
        }
        if(arr.length > 0){
            r[0].forEach((item, index) => {
                let _position=r[1][index];
                let t = this.state.mergeCellArray[_position];
                //修正struct_mode
                let c=table_model.struct_model[t[0]][t[1]];
                table_model.struct_model[t[0]][t[1]][1]=c[1]+1;
                t = [t[0], t[1], t[2], t[3]+1];
                this.state.mergeCellArray[_position]=t;
            });
        }

        //插入列

        let _row_struct_model=table_model.struct_model[p];  //当前行的struct_mode
        let _row_data_model=table_model.data_model[p];
        r[0].forEach((item, index) => {
            let _beginRow=item[0];
            let _endRow=item[2];
            for (let i = _beginRow; i <=_endRow; i++) {
                table_model.data_model[i][p]=0;
                table_model.struct_model[i][p]=[0,0];
            }
        });
    }

    /**
     * 有编辑框
     */
    hasEditInput=()=>{
        //let i,j;
        let table_mode=
        this.state.history_record[this.state.history_record.length-1];
        let editing_model=table_mode.cell_editing_model;
        for(let i=0;i<editing_model.length;i++){
            for(let j=0;j<editing_model[i].length;j++)
            {
                if(1==editing_model[i][j])
                {
                   return true;
                }
            }
        }
        return false;
    }

    render(){
        const history = this.state.history_record;
        const current = history[history.length - 1];
        let r = current.data_model.length;
        let colWidths=current.colWidths;
        //let c = this.props.colNum;  //列数
        //let c = current.data_model[current.data_model.length-1].length;  //列数  最后一列  也许保留第一列更合适?
        let c = current.data_model[0].length;
        var rows = [];
        //for (var i = 0; i < r; i++) {
        for (var i = 1; i < r; i++) {   //0行保留为“坐标”
            const rowData = current.data_model[i] || {};
            const rowValue=current.value_model[i] || {};
            const row_struct_model= current.struct_model[i] || {};
            const rowHeight=current.rowHeights[i]|| 20;
            const rowAligns = current.cell_align_model[i] || {};
            const rowIsThousandsFormat = current.cell_isThousandsFormat[i] || {};
            const rowIsPercentageFormat = current.cell_isPercentageFormat[i] || {};
            const rowDecimalPlace = current.cell_decimal_place[i] || {};

            const rowborder_tops = current.cell_border_top_model[i] || {};
            const rowborder_bottoms = current.cell_border_bottom_model[i] || {};
            const rowborder_lefts = current.cell_border_left_model[i] || {};
            const rowborder_rights = current.cell_border_right_model[i] || {};
            const rowaddFilter_brights = current.cell_addFilter_bright_model[i] || {};
            const rowcellBackgroundColors = current.cell_cellBackgroundColor_model[i] || {};
            const rowcell_font_cssArray = current.cell_cell_font_css_model[i] || {};
            const rowCell_editing_mode = current.cell_editing_model[i] || {};
            c=rowData.length;
            rows.push(this.getRows(rowData,rowValue,rowIsThousandsFormat,rowIsPercentageFormat,rowDecimalPlace,row_struct_model,rowHeight,
                rowAligns,rowborder_tops,rowborder_bottoms,rowborder_lefts,rowborder_rights,
                rowaddFilter_brights,rowcellBackgroundColors,rowcell_font_cssArray,rowCell_editing_mode,
                c, i,i));
        }
        //console.log("=========================rows==================");
        //console.log(rows);
        return (
            <div>

                <Row>
                    <Col span={12}><FormulaInputCompoent   formulaText={this.state.formulaText}/></Col>
                    <Col span={12}></Col>
                </Row>

                <div>
                    <table className="t">
                        <tbody>{this.getTableHeads(c,colWidths)}{rows}</tbody>
                    </table>
                </div>

            </div>
        )
    }
}
